PowerTCP FTP for .NET
FTP Protocol Overview


This topic gives a brief overview of the FTP protocol. For a more in-depth description, see RFC 959.


Protocol Overview

The File Transfer Protocol (FTP) provides a standard method for transferring files between computers. You can get directory listings, retrieve files, upload files, and more. A client accesses files stored on a server. A server responds to clients, providing directory and file data. FTP is different from other protocols because it uses two connections:


Control Connection

A control connection initiates a session. It is used for logging in, sending commands and receiving information. The control connection utilizes the Telnet protocol and typically uses the FTP default port 21.

Generally, a client and server make a control connection. However, a client can control file transfers between two servers. See RFC 959 for detailed information about this and other advanced features.

During login, the client sends a username and password. Some FTP servers support anonymous login where the username is "anonymous" and the password is the user's email address.

After authentication, commands are sent over the control connection. Typical commands include RETR (retrieve a file), STOR (upload a file), and QUIT (log off).

A server responds to a command with a three-digit code followed by a message. Each digit in the code has a different meaning, as shown in the following tables (the code descriptions are taken directly from the RFC):


First-Digit Codes

Code Description
1yz Positive preliminary reply. The requested action is being initiated; expect another reply before proceeding with a new command. (The user-process of sending another command before the completion reply would be in violation of protocol; but server-FTP processes should queue any commands that arrive while a preceding command is in progress.) This type of reply can be used to indicate that the command was accepted and the user-process may now pay attention to the data connection, for implementations where simultaneous monitoring is difficult. The server-FTP process may send at most, one 1yz reply per command.
2yz Positive completion reply. The requested action has been successfully completed. A new request may be initiated.
3yz Positive intermediate reply. The command has been accepted, but the requested action is being held, pending receipt of further information. The user should send another command specifying this information. This reply is used in command sequence groups.
4yz Transient negative completion reply. The command was not accepted and the requested action did not take place, but the error condition is temporary and the action may be requested again. The user should return to the beginning of the command sequence, if any. It is difficult to assign a meaning to transient, particularly when two distinct sites (Server- and User-processes) have to agree on the interpretation. Each reply in the 4yz category might have a slightly different time value, but the intent is that the user-process is encouraged to try again. A rule of thumb in determining if a reply fits into the 4yz or 5yz (Permanent Negative) category is that replies are 4yz if the commands can be repeated without any change in command form or in properties of the User or Server. For example, if the command is spelled the same with the same arguments used and the user does not change his file access or user name; then the server does not put up a new implementation.)
5yz Permanent negative completion reply. The command was not accepted and the requested action did not take place. The User-process is discouraged from repeating the exact request (in the same sequence). Even some permanent error conditions can be corrected, so the human user may want to direct his User-process to reinitiate the command sequence by direct action at some point in the future (for example, after the spelling has been changed, or the user has altered his directory status).

Second-Digit Codes

Code Description
x0z Syntax. These replies refer to syntax errors, syntactically correct commands that don't fit any functional category, unimplemented or superfluous commands.
x1z Information. These are replies to requests for information, such as status or help.
x2z Connections. Replies referring to the control and data connections.
x3z Authentication and accounting. Replies for the login process and accounting procedures.
x4z Not Defined
x45z File system. These replies indicate the status of the Server file system in relation to the requested transfer or other file system action.

Third-Digit Codes

Third-digit codes are more detailed. Refer to the RFC for these. Normally, a response consists of the code followed by a message, as shown below:

200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
226 Transfer complete.
221 Goodbye.

Data Connection

A data connection is established when a:

Once data transfer is complete, the connection is closed—it is dynamic and only one data connection exists at a time.

The connection process consists of the following steps:

  1. Client chooses an unused port number on which to accept the connection
  2. Client waits for a connection on that port
  3. Client uses the PORT command to send the port number to the server over the control connection
  4. Client sends a transfer command (for example, STOR, RETR, or LIST)
  5. Server connects to the correct port using its local port 20

Once the data connection is created, the file or directory listing is transferred and the connection is closed. Note that these steps demonstrate an "active" (non-passive) data connection, where the server connects to the client. In a "passive" connection, the client connects to a port chosen by the server.


Data Representation

Data can be transferred in different modes. File type, format control, structure, and transmission mode are all controllable. However, only file type is commonly used; the other options are generally not changed.

Of the following four file types, only ASCII and Image are commonly used:


Common Commands

The table below lists some common commands:

Command Description
ABOR Cancel the previous command issued and halt any data transfer in progress.
LIST filelist List all files and directories in the directory.
PASS password Send the user's password to the server during login.
PORT n1,n2,n3,n4,n5,n6 Send the client's IP address in the first four arguments and the port in the fifth and sixth arguments.
QUIT Log off the server.
RETR filename Retrieve a file from the server.
STOR filename Place a file on the server.
TYPE type Specify the file type.
USER username Send the user's name to the server.


PowerTCP FTP for .NET Documentation Version 6.1
© 2023 Dart Communications. All Rights Reserved.
Send comments on this topic